'use strict';

const BaseService = require('./base.js')

const modelName = 'EmailTemplate';

class EmailTemplateService extends BaseService {
    constructor(ctx) {
        super(ctx, modelName);
    }

    async create(data) {
        console.log('data',data)
        if (data.status === 1) {
            await this.ctx.model[this.modelName].update({
                status: 0
            }, {
                where: {
                    lang: data.lang || 'en'
                }
            })
        }
        return this.ctx.model[this.modelName].create(data);
    }

    async update(id, data) {
        console.log('data',data)

        if (data.status === 1) {
            await this.ctx.model[this.modelName].update({
                status: 0
            }, {
                where: {
                    lang: data.lang || 'en'
                }
            })
        }
        return this.ctx.model[this.modelName].update(data, {
            where: {
                id
            }
        })
    }
}

module.exports = EmailTemplateService;
